// pages/shop/shopDetail.js
var app = getApp()
Page({
  data: {

  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
    getSuperDetail(this)
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  infoImgClicks: function (e) {    
     console.log(e);
     var that = e.target.dataset.clickimg;
     console.log(that);
     var superdetail = this.data.superdetail;
     var urls = [];
     var str = "https://www.ymg3.com/ymgImage/supers/";
     urls.push(str + superdetail.license);
     urls.push(str + superdetail.courier);
     urls.push(str + superdetail.liveAction);
     wx.previewImage({
        current: urls[that], // 当前显示图片的http链接
        urls: urls
     })
  },
  calling: function () {
     var that = this.data.superdetail.phone;
     wx.makePhoneCall({
        phoneNumber: that, //此号码并非真实电话号码，仅用于测试
        success: function () {
           console.log("拨打电话成功！")
        },
        fail: function () {
           console.log("拨打电话失败！")
        }
     })
  }
})


function getSuperDetail(that) {
  wx.request({
    url: app.globalData.allUrl + "/YMGW/productaAction/getSupermarketSetAndInfo",
    data: {
      superID: wx.getStorageSync('superID'),
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      // success
      console.log(res.data)
      if (res.data.SuperMarketInfo) {
        var payway;
        if (res.data.SuperMarketInfo.paymentMode == 0) {
          payway = "支持货到付款及在线支付"
        } else if (res.data.SuperMarketInfo.paymentMode == 1) {
          payway = "仅支持货到付款"
        } else if (res.data.SuperMarketInfo.paymentMode == 2) {
          payway = "仅支持在线支付"
        }
        that.setData({
          superdetail: res.data.SuperMarketInfo,         
          payway: payway,
          SupermarketSet: res.data.SupermarketSet
        });     
      // console.log(res.data.SuperMarketInfo.id)   
      }      
    },
    fail: function (res) {
      // fail
    },
    complete: function (res) {
      // complete
    }, 
    
  })
}